package com.xy.modulemain.viewmodel

import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.xy.modulemain.bean.Item
import com.xy.modulemain.bean.PagingResult
import com.xy.modulemain.lisener.IBaseModelListener
import com.xy.modulemain.model.ItemModel

/**
 * @ClassName ListViewModel
 * @Author xy
 * @Date 2021/8/24 10:59
 * @Description 描述
 */
class ItemViewModel: IBaseModelListener<MutableList<Item>> {
    var itemModel = ItemModel()
    var itemList = MutableLiveData<MutableList<Item>>().apply {
        value = mutableListOf()
    }
    constructor(){
        itemModel.getCacheDataAndLoad()
        /**
         * 这里需要注册监听
         */
    }
    override fun onLoadFinish(t: MutableList<Item>, vararg pagingResult: PagingResult) {
        itemList.value?.clear()
        itemList.value?.addAll(t)
        itemList.postValue(itemList.value)
    }

    override fun onLoadFailure(prompt: String) {

    }
}